<?php
namespace app\log\controller;
use app\common\controller\Common;
use think\Request;
class Log extends Common
{
	protected $model = null;
	protected $keyword_search = [];

	public function _initialize(){
		parent::_initialize();
		$this->model = model('Log');
	}

	/**
	 * 操作日志列表
	 */
	public function index()
	{
		if(Request()->isGet()){
			if(Request()->isAjax()){
				$data = input('get.');
				return $this->getList($data);
			}
			$this->assign('admin',$this->model->getAdmin());
			$this->assign('type',$this->model->getType());
			return $this->fetch('');
		}
	}

	/**
	 * 列表查询条件处理
	 * @param array $data 查询参数
	 */
	protected function handleList($data)
	{
		$where = [];
		/*@类型*/
		if(isset($data['type']) && $data['type'] != ''){
			$where['type'] = $data['type'];
		}
		/*@操作者*/
		if(isset($data['admin_id']) && $data['admin_id'] != ''){
			$where['admin_id'] = $data['admin_id'];
		}
		/*@时间*/
		if(isset($data['time_type'])){
			if($data['time_type'] == 1){
				//本月
				$where['addtime'] = [
					['egt', mktime(0,0,0,date('m'),1,date('Y'))],
					['lt', mktime(0,0,0,date('m')+1,1,date('Y'))]
				];
			}else if($data['time_type'] == 2){
				//上月
				$where['addtime'] = [
					['egt', mktime(0,0,0,date('m')-1,1,date('Y'))],
					['lt', mktime(0,0,0,date('m'),1,date('Y'))]
				];
			}else if($data['time_type'] == 3){
				//自定义
				if(isset($data['start']) && $data['start'] != '' && isset($data['end']) && $data['end'] != ''){
					$where['addtime'] = [
						['egt', strtotime($data['start'])],
						['lt', strtotime($data['end'])]
					];
				}else if(isset($data['start']) && $data['start'] != ''){
					$where['addtime'] = ['egt', strtotime($data['start'])];
				}else if(isset($data['end']) && $data['end'] != ''){
					$where['addtime'] = ['lt', strtotime($data['end'])];
				}
			}
		}
		
		return $where;
	}
}